package com.base.sort;

import java.util.Arrays;

/**
 * TODO
 *
 * @author leon
 * @date 2021年12月02日 20:04
 */
public class FindRelativeRanks {
    public String[] findRelativeRanks(int[] score) {
        int n = score.length;
        String[] desc = {"Gold Medal", "Silver Medal", "Bronze Medal"};
        int[][] arr = new int[n][2];
        // 将排序元素和位置进行一个绑定
        for (int i = 0; i < n; ++i) {
            arr[i][0] = score[i];
            arr[i][1] = i;
        }
        Arrays.sort(arr, (a, b) -> b[0] - a[0]);
        String[] ans = new String[n];
        for (int i = 0; i < n; ++i) {
            if (i >= 3) {
                ans[arr[i][1]] = Integer.toString(i + 1);
            } else {
                ans[arr[i][1]] = desc[i];
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        new FindRelativeRanks().findRelativeRanks(new int[]{2,3,4,1,0,5});
    }
}
